<?php


namespace App\Http\Controllers\Admin;


use App\Tool\Json;

class MenuController extends AuthCheckController
{

    /**
     * @Auth(type='skip_auth')
     * Create by Peter
     * 2019/08/28 11:43:35
     * Email:904801074@qq.com
     * @return false|string
     */
    function getMenu()
    {

        $allMenu = config('user.menu');

        $allRule = resolve('allRule');

        if ($allRule === true) return Json::code(1, 'success', $allMenu);

        foreach ($allMenu as $key => $value) {

            foreach ($value['children'] as $k => $v) {

                $apiPath = $v['apiPath'] ?? null;

                if(!$apiPath) continue;

                if (!in_array($apiPath, $allRule)) unset($allMenu[$key]['children'][$k]);


            }
            //清除空模块
            if (!$allMenu[$key]['children']) unset($allMenu[$key]);

        }

        return Json::code(1, $allRule, $allMenu);
    }


}
